package com.duobaoyu.dby.supply.db.repository.order.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.duobaoyu.dby.common.mybatis.base.DbyServiceImpl;
import com.duobaoyu.dby.common.mybatis.support.ParamConvert;
import com.duobaoyu.dby.supply.common.biz.bo.order.OrderAmountStatisticsBO;
import com.duobaoyu.dby.supply.common.biz.bo.order.OrderExportBO;
import com.duobaoyu.dby.supply.common.biz.bo.order.OrderListBO;
import com.duobaoyu.dby.supply.common.biz.dto.order.OrderPageDTO;
import com.duobaoyu.dby.supply.common.biz.dto.order.OrderStatisticsAmountDTO;
import com.duobaoyu.dby.supply.db.entity.order.Order;
import com.duobaoyu.dby.supply.db.mapper.order.OrderMapper;
import com.duobaoyu.dby.supply.db.repository.order.OrderRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * 订单
 *
 * @author fengshaoyu
 * @version 1.0.0
 * @date 2023/10/7 10:32
 */
@Repository
@RequiredArgsConstructor
public class OrderRepositoryImpl extends DbyServiceImpl<OrderMapper, Order> implements OrderRepository {

    @Override
    public int updateOrder(LambdaUpdateWrapper<Order> wrapper) {
        return this.getBaseMapper().update(null, wrapper);
    }

	@Override
	public IPage<OrderListBO> queryOrderPage(OrderPageDTO orderPage){
		IPage<OrderListBO> page = this.getBaseMapper().queryOrderPage(ParamConvert.getPage(orderPage).setSearchCount(false), orderPage);
		int totalCount = this.queryOrderPageCount(orderPage);
		page.setTotal(totalCount);
		page.setSize(orderPage.getSize());
		page.setCurrent(orderPage.getCurrent());
		return page;
	}

	@Override
	public List<OrderExportBO> listOrderExportInfo(OrderPageDTO orderPage){
		return this.getBaseMapper().listOrderExportInfo(orderPage);
	}

	@Override
	public int countOrderExportInfo(OrderPageDTO orderPage){
		return this.getBaseMapper().countOrderExportInfo(orderPage);
	}

	@Override
	public int queryOrderPageCount(OrderPageDTO orderPage) {
		return this.getBaseMapper().queryOrderPageCount(orderPage);
	}

    @Override
    public List<OrderAmountStatisticsBO> statisticsAmount(OrderStatisticsAmountDTO orderStatisticsAmount) {
		List<OrderAmountStatisticsBO> orderAmountStatisticsList = this.getBaseMapper().statisticsAmount(orderStatisticsAmount);
		return Optional.ofNullable(orderAmountStatisticsList).orElse(Collections.emptyList());
    }

	@Override
	public List<Order> noLogisticsOrders(Integer page, Integer pageSize) {
		return this.getBaseMapper().noLogisticsOrders(page,pageSize);
	}

}
